﻿using System;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Ink;
using System.Windows.Media;
using ThePresenter.Data.Presentation.Polls;
using ThePresenter.ViewModel;

namespace ThePresenter.Data.Presentation
{
	public sealed class Slide : ViewModelBase, ISerializable
	{
		#region Fields

		readonly UID _uid;

		readonly Brush _background;

		readonly StrokeCollection _strokes;

		readonly Presentation _presentation;

		readonly PollCollection _polls;

		Size _size;

		#endregion

		#region Properties

		public UID Uid
		{
			get
			{
				return _uid;
			}
		}

		public Brush Background
		{
			get
			{
				return _background;
			}
		}

		public StrokeCollection Strokes
		{
			get
			{
				return _strokes;
			}
		}

		public Presentation Presentation
		{
			get
			{
				return _presentation;
			}
		}

		public Size Size
		{
			get
			{
				return _size;
			}
			set
			{
				if (_size != value)
				{
					_size = value;
					OnPropertyChanged("Size");
				}
			}
		}

		public bool IsSelected
		{
			get
			{
				if (Presentation == null)
					throw new InvalidOperationException("Presentation is not set.");

				return false;

				//return Presentation.SelectedSlide == this;
			}
		}

		public PollCollection Polls
		{
			get
			{
				return _polls;
			}
		}

		#endregion

		/// <summary>
		/// Initializes a new instance of the <see cref="Slide"/> class.
		/// </summary>
		/// <param name="presentation">The presentation that this instance belongs to.</param>
		public Slide(Presentation presentation)
		{
			if (presentation == null)
				throw new ArgumentNullException("presentation"); 

			_presentation = presentation;
			_uid = new UID();
			_strokes = new StrokeCollection();
			_background = Brushes.White;
			_polls = new PollCollection();
		}

		#region ISerializable Members

		/// <summary>
		/// Initializes a new instance of the <see cref="Slide"/> class.
		/// </summary>
		/// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data.</param>
		/// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination. .</param>
		public Slide(SerializationInfo info, StreamingContext context)
		{
			// uid
			// _background
			// _strokes
			// _presentation
			// _size
			// _polls
		}

		/// <summary>
		/// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data.</param>
		/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization.</param>
		/// <exception cref="T:System.Security.SecurityException">
		/// The caller does not have the required permission.
		/// </exception>
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			// info.AddValue("Guid", _guid.ToByteArray(), typeof(byte[]));
		}

		#endregion
	}
}
